#include "TimerTask.h"

TimerTask::TimerTask(uint64_t id, uint32_t delay, const TaskFunc &cb)
    : _id(id),
      _timeout(delay),
      _canceled(false),
      _task_cb(cb)
{
}
TimerTask::~TimerTask()
{
    if (_canceled == false)
        _task_cb();
    _release();
}

// 1. 设置定时器任务的释放
void TimerTask::SetRelease(const ReleaseFunc &cb)
{
    _release = cb;
}

// 2. 获取当前定时任务超时时间
uint32_t TimerTask::DelayTime()
{
    return _timeout;
}

void TimerTask::Cancel()
{
    _canceled = true;
}